import request from "@/utils/request";
const defaultApi = (apiName) => {
    return {
        list: (params) => request.get(`/${apiName}/list`, { params }),
        page: (params) => request.get(`/${apiName}`, { params }),
        read: (id) => request.get(`/${apiName}/` + id),
        create: (id, data) => request.post(`/${apiName}`, data),
        update: (id, data) => request.put(`/${apiName}/` + id, { ...data, create_time: undefined, id: undefined }),
        delete: (id) => request.delete(`/${apiName}/` + id)
    }
}
export const http = {
    login: (data) => request.post('/user/login', data),
    menu: defaultApi('menu'),
    role: defaultApi('role'),
    user: {
        ...defaultApi('user'),
        getUserInfo: (userId) => request.get(`/user/getUserInfo`, { params: { userId }}),
        getUserRoles: (userId) => request.get(`/user/getUserRoles`, { params: { userId }}),
        updateUserRoles: (data) => request.post(`/user/updateUserRoles`, data),
    },
    banner: defaultApi('banner'),
    news: defaultApi('news'),
    policy: defaultApi('policy'),
    category: defaultApi('category'),
    product: defaultApi('product'),
    food: defaultApi('food'),
}
// uploadFile
export const uploadFile = (file) => {
    const formData = new FormData()
    formData.append('file', file)
    return request({
        url: '/upload/file',
        method: 'post',
        data: formData
    })
}
